home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / e / gencodee_v21.lha / GenCodeE / E / DemoGenCodeE21b / DemoGenCodeE.e < prev    next >
Text File  |  1994-11-15  |  7KB  |  213 lines

  1. OPT OSVERSION = 37
  2. OPT TURBO
  3.  
  4.  
  5. /* ////////////////////////////////////////////////////////////////////////////
  6. //////////////////////////////////////////////////////// External modules /////
  7. //////////////////////////////////////////////////////////////////////////// */
  8. MODULE 'locale'
  9. MODULE 'icon'
  10.  
  11. PMODULE 'GUI'
  12.  
  13.  
  14. /* ////////////////////////////////////////////////////////////////////////////
  15. ////////////////////////////////////////////////////// Exception handling /////
  16. //////////////////////////////////////////////////////////////////////////// */
  17. RAISE    "MEM"    IF    New()    =    NIL
  18.  
  19.  
  20. /* ////////////////////////////////////////////////////////////////////////////
  21. //////////////////////////////////////////////////////// Global variables /////
  22. //////////////////////////////////////////////////////////////////////////// */
  23. DEF dgce    :    PTR TO app_obj    /* look at GUI.e for "app_obj" object */
  24. DEF string_var    :    PTR TO CHAR    /* used by a notification (see GUI.e line 154) */
  25.  
  26.  
  27. /* ////////////////////////////////////////////////////////////////////////////
  28. ////////////////////////////////////////////////////////// Main Procedure /////
  29. //////////////////////////////////////////////////////////////////////////// */
  30. PROC main() HANDLE
  31.  
  32.     DEF running = TRUE , result_domethod , signal , mui_error
  33.     DEF arexx : app_arexx , display : app_display
  34.     DEF change_text_hook : hook , arexx_commands : PTR TO mui_command
  35.     DEF icon = NIL
  36.  
  37.         /* needed libraries and icon init */
  38.     IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) ) = NIL THEN Raise( "muim" )
  39.     IF ( iconbase := OpenLibrary( 'icon.library' , 0 ) ) THEN icon := GetDiskObject( 'PROGDIR:DemoGenCodeE' ) ELSE Raise( "icon" )
  40.  
  41.         /* exported variables init */
  42.     string_var := 'String variable put !'
  43.  
  44.         /* MUI GUI init */
  45.             /* in GUI.e line 17, you can see the declaration of "app_display" object */
  46.             /* each field of this object correspond to a hook function declared in MUIBuilder */
  47.             /* in the present case, there is only the "button_pressed" hook function (see GUI.e line 166) */
  48.     installhook( display.button_pressed , {button_pressed} )
  49.  
  50.         /* ARexx init */
  51.             /* for ARexx init you must fill an "app_arexx" object defined in GUI.e line 12 */
  52.             /* this object gets 2 fields : one for the commands and one for the arexx error hook function */
  53.     installhook( change_text_hook , {change_text} )
  54.     arexx.commands := ( arexx_commands := New( ( SIZEOF mui_command ) * 2 ) )
  55.     arexx_commands[].mc_name := 'change_text'
  56.     arexx_commands[].mc_template := ''
  57.     arexx_commands[].mc_parameters := 0
  58.     arexx_commands[].mc_hook := change_text_hook
  59.     installhook( arexx.error , {arexx_error} )
  60.  
  61.         /* MUI application creation */
  62.             /* for this you call the create method (see GUI.e line 43) on the "app_obj" object */
  63.             /* to this method, you must give the "app_display" object */
  64.             /* and if you want (not obliged), you can give an icon, the "app_arexx" object and a menu object (obsolete) */
  65.     IF ( dgce := create_app( display , icon , arexx , NIL ) ) = NIL THEN Raise( "MUI" )
  66.     init_notifications_app( dgce , display )
  67.  
  68.         /* Main loop */
  69.     WHILE running
  70.  
  71.         result_domethod := domethod( dgce.app , [ MUIM_Application_Input , {signal} ] )
  72.         SELECT result_domethod
  73.  
  74.             CASE ID_BUTTON_PRESSED    /* see GUI.em line 37 for the definition of this ID */
  75.  
  76.                 set( dgce.tx_result , MUIA_Text_Contents , 'Modifed by ID returned !' )
  77.  
  78.             CASE MUIV_Application_ReturnID_Quit
  79.  
  80.                 running := FALSE
  81.  
  82.         ENDSELECT
  83.  
  84.         IF ( signal AND running ) THEN Wait( signal )
  85.  
  86.     ENDWHILE
  87.  
  88.     dispose_app( dgce )
  89.     IF icon            THEN FreeDiskObject( icon )
  90.     IF iconbase        THEN CloseLibrary( iconbase )
  91.     CloseLibrary( muimasterbase )
  92.  
  93. EXCEPT
  94.  
  95.     SELECT exception
  96.  
  97.         CASE "muim"
  98.  
  99.             error_simple( 'Can''t open muimaster.library !' )
  100.  
  101.         CASE "icon"
  102.  
  103.             error_simple( 'Can''t open icon.library !' )
  104.  
  105.         CASE "MEM"
  106.  
  107.             error( 'Not enough memory !' )
  108.  
  109.         CASE "MUI"
  110.  
  111.             mui_error := Mui_Error()
  112.  
  113.             SELECT mui_error
  114.  
  115.                 CASE MUIE_OutOfMemory
  116.  
  117.                     error_simple( 'Not enough memory !' )
  118.  
  119.                 CASE MUIE_OutOfGfxMemory
  120.  
  121.                     error_simple( 'Not enough chip memory !' )
  122.  
  123.                 CASE MUIE_MissingLibrary
  124.  
  125.                     error_simple( 'Can''t open a needed library !' )
  126.  
  127.                 CASE MUIE_NoARexx
  128.  
  129.                     error_simple( 'Can''t create arexx port !' )
  130.  
  131.                 DEFAULT
  132.  
  133.                     error_simple( 'Internal problem !' )
  134.  
  135.             ENDSELECT
  136.  
  137.     ENDSELECT
  138.  
  139.     IF dgce            THEN dispose_app( dgce )
  140.     IF icon            THEN FreeDiskObject( icon )
  141.     IF iconbase        THEN CloseLibrary( iconbase )
  142.     IF muimasterbase    THEN CloseLibrary( muimasterbase )
  143.  
  144. ENDPROC
  145.  
  146.  
  147. /* ////////////////////////////////////////////////////////////////////////////
  148. ///////////////////// Prints an error message with an intuition requester /////
  149. //////////////////////////////////////////////////////////////////////////// */
  150. PROC error_simple( message : PTR TO CHAR ) RETURN EasyRequestArgs(    NIL , [ 20 , 0 ,
  151.                                     'DemoGenCodeE error !' ,
  152.                                     message ,
  153.                                     '_OK' ] , NIL , NIL )
  154.  
  155.  
  156. /* ////////////////////////////////////////////////////////////////////////////
  157. /////////////////////////// Prints an error message with an MUI requester /////
  158. //////////////////////////////////////////////////////////////////////////// */
  159. PROC error( message : PTR TO CHAR ) RETURN Mui_RequestA(    dgce.app ,
  160.                                 dgce.wi_the_window ,
  161.                                 NIL ,
  162.                                 'DemoGenCodeE error !' ,
  163.                                 '*_OK' ,
  164.                                 message ,
  165.                                 NIL )
  166.  
  167.  
  168. /* ////////////////////////////////////////////////////////////////////////////
  169. /////////// Hook function called each time bt_call_hook button is pressed /////
  170. //////////////////////////////////////////////////////////////////////////// */
  171. PROC button_pressed( hook , obj , msg ) RETURN set( dgce.tx_result , MUIA_Text_Contents , 'Modified by called hook function !' )
  172.  
  173.  
  174. /* ////////////////////////////////////////////////////////////////////////////
  175. /////////////////////// Hook function called by ARexx command change_text /////
  176. //////////////////////////////////////////////////////////////////////////// */
  177. PROC change_text( hook , obj , msg ) RETURN set( dgce.tx_result , MUIA_Text_Contents , 'Modifed by ARexx command change_text !' )
  178.  
  179.  
  180. /* ////////////////////////////////////////////////////////////////////////////
  181. ////////////////////////// Hook function called by ARexx in case of error /////
  182. //////////////////////////////////////////////////////////////////////////// */
  183. PROC arexx_error( hook , obj , msg ) RETURN error_simple( 'Unknown ARexx command recieved !' )
  184.  
  185.  
  186. /* ////////////////////////////////////////////////////////////////////////////
  187. ///////////////////////// Directly taken from the Amiga v3.0 distribution /////
  188. //////////////////////////////////////////////////////////////////////////// */
  189. PROC installhook(hook,func)
  190.  
  191.     DEF return
  192.  
  193.     MOVE.L    hook,A0
  194.     MOVE.L    func,12(A0)
  195.     LEA    hookentry(PC),A1
  196.     MOVE.L    A1,8(A0)
  197.     MOVE.L    A4,16(A0)
  198.     MOVE.L    A0,return
  199.  
  200. ENDPROC return
  201.  
  202. hookentry:
  203.     MOVEM.L    D2-D7/A2-A6,-(A7)
  204.     MOVE.L    16(A0),A4
  205.     MOVE.L    A0,-(A7)
  206.     MOVE.L    A2,-(A7)
  207.     MOVE.L    A1,-(A7)
  208.     MOVE.L    12(A0),A0
  209.     JSR    (A0)
  210.     LEA    12(A7),A7
  211.     MOVEM.L    (A7)+,D2-D7/A2-A6
  212.     RTS
  213.